package com.zdxc.controller;


import com.zdxc.entities.CodeAddress;
import com.zdxc.entities.Userinfo;
import com.zdxc.service.AddressService;
import com.zdxc.service.UserService;
import common.bean.Paging;
import common.bean.ResultJsonWrap;
import common.util.StringEncrypt;
import common.util.UserInfoUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping(value="/address/*")
public class AddressController {
    @Autowired
    private AddressService addressService;

    @RequestMapping("/getid")
    @ResponseBody
    public CodeAddress getUser(@RequestParam("id") String zyzId){
       return  addressService.findByKey(zyzId);
    }

    /**
     * 分页返回
     * @param addressName ,addressCode , addressArea
     * @param paging
     * @return
     */
    @RequestMapping("/getcondition")
    @ResponseBody
    public Paging getusers(@RequestParam(name="addressName",defaultValue="") String addressName,
                           @RequestParam(name="addressCode",defaultValue="") String addressCode,
                           @RequestParam(name="addressArea",defaultValue="") String addressArea,
                           Paging paging){
        CodeAddress address =new CodeAddress();
        address.setAddressArea(addressArea);
        address.setAddressCode(addressCode);
        address.setAddressName(addressName);

        Paging resultPage =addressService.findByCondition(address,paging);
        return  resultPage;
    }

    @RequestMapping(value="/list")
    public String list(){
        return "address/list";
    }




    @RequestMapping(value="/add")
    public String add(){
        return "address/add";
    }


    @RequestMapping(value="/delete")
    @ResponseBody
    public ResultJsonWrap  delete(String userId){
        ResultJsonWrap resultJsonWrap = new ResultJsonWrap();
        int  result = addressService.deleteByPrimaryKey(userId);
        if (result>0)
            resultJsonWrap.setMsg("删除成功");
        else
            resultJsonWrap.setErrorMsg("添加失败");
        return resultJsonWrap;
    }

}
